import functools
class Solution(object):
    def canWin(self, currentState):
        """
        :type currentState: str
        :rtype: bool
        """
        @functools.cache
        def judge_child(s):
            if s == '+':
                return 0
            else:
                if s == '++' or s == '+++':
                    return 1
                else:
                    s = list(s)
                    gx = set()
                    for i in range(len(s) - 1):
                        new_s = s.copy()
                        new_s[i] = '-'
                        new_s[i + 1] = '-'
                        gx.add(search(''.join(new_s)))
                    index = 0
                    while index in gx:
                        index += 1
                    return index

        def search(state):
            state = state.split('-')
            new_state = []
            gx = []
            for item in state:
                if item not in ['']:
                    new_state.append(item)
            if not new_state:
                return 0
            else:
                for s in new_state:
                    gx.append(judge_child(s))
                out = gx[0]
                for i in range(1, len(gx)):
                    out = out ^ gx[i]
                return out

        if search(currentState):
            return True
        else:
            return False


data = Solution()
currentState = "++++++"
print(data.canWin(currentState))
